let searchPage = document.querySelector('.search-page');
let inputSubmit = document.querySelector('.input-submit');
let inputWords = document.querySelector(".input-words");

// 添加搜索结果
function addSection(content, storeName, href) {

    var newSection = document.createElement('section');
    var newDiv = document.createElement('div');
    var newSectionP1 = document.createElement('p');
    var newSectionP2 = document.createElement('p');
    var newSectionA = document.createElement('a');

    newSectionP1.textContent = content;
    newSectionP2.textContent = storeName;
    newDiv.setAttribute('class', 'detailContent');
    newSectionA.setAttribute('href', href);
    newSectionA.setAttribute('target', "_blank");
    var node = document.createTextNode("详情");
    newSectionA.appendChild(node);
    newDiv.appendChild(newSectionP1);
    newDiv.appendChild(newSectionP2);
    newSection.appendChild(newDiv);
    newSection.appendChild(newSectionA);
    searchPage.appendChild(newSection);
}
//后端处理的结果已经送到message中
function transfer_to_front (message, userName='bqr', userPortrait=13){
    console.log(message);
    searchPage.innerHTML = "";
    for (let i = 0; i < message.length; i++) {
        addSection(message[i][0], message[i][1], message[i][2])
    }
}
//搜索按钮触发响应
function getUsersSearch() {
    //搜索框内容传给后端
    eel.transfer_to_back(inputWords.value);
    //等待数据从后端返回
    eel.expose(transfer_to_front);
}

//搜索按钮添加事件
inputSubmit.addEventListener('click', getUsersSearch);





